"""
Author: wenbin
Create: 2024-09-03
"""
import uuid

from sqlalchemy import Column, UUID, Text, Float, Integer, Index

from .base_model import BaseModel


class Message(BaseModel):
    """消息模型"""

    __tablename__ = "message"
    __table_args__ = (
        Index("idx_message_conversation_id", "conversation_id"),
        {"comment": "消息表"}
    )

    id = Column(UUID, default=uuid.uuid4, primary_key=True, comment="id")
    conversation_id = Column(UUID, nullable=False, comment="会话 id")
    question = Column(Text, nullable=False, comment="用户提问")
    answer = Column(Text, nullable=False, comment="AI 回答")
    expand_tokens = Column(Integer, nullable=False, comment="消耗 tokens")
    response_time = Column(Float, nullable=False, comment="响应耗时")
